<template>
  <div class="hot-con">
    <div class="title">新歌推荐</div>
    <div class="content">
      <div class="item" v-for="item in recom" :key="item.id" @click="goPlay(item)">
        <div class="img">
          <img :src="item.picUrl + '?param=200y200'" />
        </div>
        <div class="songName">{{ item.name }}</div>
      </div>
    </div>

    <div class="title">最新专辑</div>
    <div class="content">
      <div class="item" v-for="item in newestAlbum" :key="item.id" @click="goList(item)">
        <div @click="toList(item, 'album')">
          <div class="img">
            <img :src="item.blurPicUrl + '?param=200y200'" alt="" />
          </div>
          <div class="songName">{{ item.name }}</div>
        </div>
      </div>
    </div>

    <div class="title">热门歌手</div>
    <div class="content">
      <div class="item" v-for="item in artistsList" :key="item.id">
        <div @click="toList(item, 'artists')">
          <div class="img">
            <img :src="item.img1v1Url + '?param=200y200'" />
          </div>
          <div class="songName">{{ item.name }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { recomNew, artists, newest, recomSongs, albumDteail } from '../../request/api'

export default {
  data() {
    return {
      recom: [], //推荐 用户未登录显示推荐新音乐 用户已经登录显示推荐音乐
      artistsList: [], //热门歌手列表
      newestAlbum: [], //最新专辑列表
    }
  },
  created() {
    recomNew().then(res => {
      if (res.code === 200) {
        this.recom = res.result
      }
    })

    artists().then(res => {
      if (res.code === 200) {
        this.artistsList = res.artists
      }
    })
    newest().then(res => {
      if (res.code === 200) {
        this.newestAlbum = res.albums.slice(0, 10)
      }
    })
  },

  methods: {
    goList({ id }) {
      albumDteail({ id }).then(res => {
        console.log(res)
      })
    },

    goPlay({ id }) {
      this.$router.push({ name: 'musicPlay', params: { id } })
    },

    toList({ id }, type) {
      this.$router.push({ name: 'musicList', params: { type, id } })
    },
  },
}
</script>

<style lang="less" scoped>
.hot-con {
  width: 1200px;
  margin: auto;

  .title {
    font-weight: 700;
    line-height: 2;
  }

  .content {
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: auto;

    grid-row-gap: 20px;
    grid-column-gap: 40px;

    font-size: 14px;

    .item {
      .img {
        width: 100%;

        img {
          width: 100%;
        }
      }

      .songName {
        line-height: 2;
      }
    }
  }
}
</style>
